<?php
  require_once('./db.php');
  $users = fetchAll('users');

  $fileName = time().'.csv';
  $file = 'tmp/'.$fileName;
  $fp = fopen($file, 'w+');
  //var_dump($fp);

  #############################
  $struct = descTable('users');
  fputcsv($fp,$struct);
  #############################


while($ans = mysql_fetch_assoc($users)) {
  fputcsv($fp,$ans);
}


if(is_file($file)) {
  header('Content-Description: File Transfer');
  header('Content-Type: application/force-download');
  header('Content-Length: ' . filesize($file));
  header('Content-Disposition: attachment; filename=' . $fileName);
  readfile($file);
  fclose($fp);
  unlink($file);
  exit;
}

  require_once("footer.php");
?>

